package com.magiccompass.alipay.barcode.signature;

import java.security.MessageDigest;

public class MD5Signature {
	public static String getMD5String(String str) throws Exception{
		String returnValue;
		try {
			StringBuffer sb = new StringBuffer();
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(str.getBytes());
			
			byte byteData[] = md.digest();
   
			for (int i = 0; i < byteData.length; i++) {
			 sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
			}
			returnValue = sb.toString();
		} catch (Exception e) {
			returnValue = null;
			e.printStackTrace();
			throw e;
		}
		return returnValue;
	}
	public static void main(String[] args){
		String testStr = "test01";
		try {
			System.out.println(getMD5String(testStr));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}